<template>
  <div>
    <div class="container">
      <h1 style="text-align: center; margin-bottom: -30px;">库存</h1>
      <div :class="className" class="echart"></div>
    </div>

  </div>
</template>

<script>
export default {
  props: {
    className: String
  },
  // 页面初始化挂载dom
  mounted() {
    this.getLoadEcharts()
  },
  methods: {
    getLoadEcharts() {
      let c = '.' + this.className
      var myChart = this.$echarts.init(document.querySelector(c))

      var colorList = ["#4FE894", "#EF0C27", "#FEE7EA", '#3366dD', '#FEC574']
      var listData = [
        { name: "唇妆", value: 30 },
        { name: "刷具", value: 10 },
        { name: "底妆", value: 20 },
        { name: "眼妆", value: 20 },
        { name: "护肤", value: 10 },
      ]
      var option = {
        color: colorList,
        title: {
          x: "center",
          y: "center",
          textStyle: {
            color: "#000",
            fontSize: 20,
          },
        },
        legend: {
          orient: "vertical",
          bottom: 5,
          align: "right",
          right: 15,
          textStyle: {
            color: "#000",
            fontSize: 20,
          },
          selectedMode: false,
          data: ["元素1", "元素2", "元素3"],
        },
        tooltip: {
          trigger: "item",
        },
        series: [
          {
            type: "pie",
            center: ["50%", "50%"],
            radius: ["55%", "35%"],
            itemStyle: {
              normal: {
                color: function (params) {
                  return colorList[params.dataIndex]
                },
              },
            },
            label: {
              show: true,
              fontSize: 10,
              color: "#000",
              formatter: function (data) {
                return data.name + ":" + data.percent.toFixed(0) + "%"
              },
            },
            labelLine: {
              normal: {
                length: 15,
                length2: 15,
                lineStyle: {
                  width: 2,
                },
              },
            },
            data: listData,
          },
        ],
      }
      myChart.setOption(option)
    },
  },
}
</script>

<style lang="scss" scoped>
.container {
  width: 400px;
  height: 400px;
  // margin-left: 30px;
  /* display: flex; */
}

.echart {
  width: 100%;
  height: 100%;
}
</style>